package com.fengye.school.controller;

import com.fengye.school.dto.major.MajorVO;
import com.fengye.school.model.school.Major;
import com.fengye.school.response.ResponsePageResult;
import com.fengye.school.service.MajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 专业设置控制器
 * @author sky
 * @date 2021/4/22 10:58
 */
@RestController
@RequestMapping("/major")
public class MajorController {

    @Autowired
    private MajorService majorService;

    @PostMapping("/save")
    public Major save(@RequestBody Major major) {
        return majorService.save(major);
    }

    @GetMapping("/list")
    public List<MajorVO> list() {
        return majorService.list();
    }

    @GetMapping("/list/page")
    public ResponsePageResult<Major> listByPage(int page, int limit) {
        return majorService.listByPage(Math.max((page - 1), 0), limit);
    }

    @DeleteMapping("/delete/all")
    public void deleteAll(Long[] ids){
        Arrays.stream(ids).forEach(System.out::println);
        majorService.deleteAll(ids);
    }

    @DeleteMapping("/delete/id/{id}")
    public void deleteById(@PathVariable(name = "id", required = true)Long id){
        majorService.deleteById(id);
    }
    

    // @PostMapping("/save")
    // public MajorVO save(@RequestBody MajorSaveDTO major){
    //     return majorService.save(major);
    // }
    //
    // @PostMapping("/save2")
    // public Major save(@RequestBody Major major){
    //     return majorService.save2(major);
    // }
    //
    // @GetMapping("/list")
    // public List<MajorVO> list() {
    //     return majorService.list();
    // }
    //
    // @GetMapping("/list/page")
    // public PageVO<MajorVO> listForPage(@RequestParam(name = "page", defaultValue = "1") int page,
    //                                  @RequestParam(name = "size", defaultValue = "5")int size) {
    //     return majorService.listForPage(page, size);
    // }
    //
    // @GetMapping("/list/page2")
    // public PageVO<Major> listForPage2(@RequestParam(name = "page", defaultValue = "1") int page,
    //                                   @RequestParam(name = "size", defaultValue = "5")int size) {
    //     return majorService.listForPage2(page, size);
    // }
}
